package com.enjoyor.soa.traffic.rest.efoms.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.enjoyor.soa.traffic.api.dto.efoms.CheckRecodeInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.RepairsInfoDto;
import com.enjoyor.soa.traffic.api.dto.efoms.TemplateDto;
import com.enjoyor.soa.traffic.api.dto.efoms.VideoRelationInfoDto;
import com.enjoyor.soa.traffic.api.dto.tsms.RltRoutePostDto;
import com.enjoyor.soa.traffic.frame.annotation.Auth;
import com.enjoyor.soa.traffic.frame.security.bean.dto.UserDto;
import com.enjoyor.soa.traffic.rest.efoms.dubbo.IVideoRelationInfoConsumeService;
import com.enjoyor.soa.traffic.util.pojo.Page;
import com.enjoyor.soa.traffic.util.pojo.ResultPojo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;

@Auth
@RestController
@RequestMapping({ "/videoRelation" })
@Api("CheckRecordInfoController")
@CrossOrigin
public class VideoRelationInfoController {

	@Autowired
	private IVideoRelationInfoConsumeService videoRelationInfoConsumeService;

	/**
	 * 获取关联对象；
	 * 
	 * @param videoRelationId
	 * @return
	 */
	@GetMapping(value = { "getVideoRelationInfo" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoRelationInfoDto.class, code = 0, message = "")
	@ApiOperation("获取关联视频对象信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "videoRelationId", value = "关联编号", paramType = "query", dataType = "String") })
	public ResultPojo getVideoRelationInfo(
			@RequestParam(defaultValue = "", value = "videoRelationId", required = false) String videoRelationId,
			HttpServletRequest request) {
		return videoRelationInfoConsumeService.getVideoRelationInfo(videoRelationId);
	}

	/**
	 * 获取关联List
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getVideoRelationInfoList" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoRelationInfoDto.class, code = 0, message = "")
	@ApiOperation("获取巡检记录List")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "videoRelationId", value = "视频关联编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "key", value = "点位名称或编号", paramType = "query", dataType = "String") })
	public ResultPojo getVideoRelationInfoList(
			@RequestParam(defaultValue = "", value = "videoRelationId", required = false) String videoRelationId,
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			HttpServletRequest request) {
		return videoRelationInfoConsumeService.getVideoRelationList(videoRelationId, videoGroupId,key);
	}

	/**
	 * 获取关联Page
	 * 
	 * @param CheckRecordInfoId
	 * @return
	 */
	@GetMapping(value = { "/getVideoRelationInfoPage" }, produces = { "application/json; charset=UTF-8" })
	@ResponseBody
	@ApiResponse(response = VideoRelationInfoDto.class, code = 0, message = "")
	@ApiOperation("获取巡检记录Page")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "videoRelationId", value = "视频关联编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String"),
			@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String")})
	public ResultPojo getVideoRelationInfoPage(
			@RequestParam(defaultValue = "", value = "videoRelationId", required = false) String videoRelationId,
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			@RequestParam(defaultValue = "", value = "key", required = false) String key,
			HttpServletRequest request, Page page) {
		return videoRelationInfoConsumeService.getVideoRelationPage(videoRelationId, videoGroupId,key,page);
	}

	/**
	 * 添加关联；
	 * @param videoRelationInfoDto
	 * @return
	 */
	@PostMapping(value = { "/insertVideoRelationInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("添加天联信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "videoGroupId", value = "视频分组编号", paramType = "query", dataType = "String") })
	public ResultPojo insertVideoRelationInfo(@RequestBody List<VideoRelationInfoDto> rltList,
			@RequestParam(defaultValue = "", value = "videoGroupId", required = false) String videoGroupId,
			HttpServletRequest request) {
		return videoRelationInfoConsumeService.insertVideoRelationInfo(rltList,videoGroupId,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 修改关联；
	 * @param videoRelationInfoDto
	 * @return
	 */
	@PostMapping(value = { "/updateVideoRelationInfo" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("修改关联信息")
	public ResultPojo updateVideoRelationInfo(@RequestBody VideoRelationInfoDto videoRelationInfoDto, HttpServletRequest request) {
		return videoRelationInfoConsumeService.updateVideoRelationInfo(videoRelationInfoDto,
				((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
	
	/**
	 * 删除关联信息；
	 * @param VideoGroupId
	 * @param request
	 * @return
	 */
	@DeleteMapping(value = { "/deleteVideoRelationInfo" }, produces = { "application/json; charset=UTF-8" })
    @ResponseBody
    @ApiOperation("删除巡检记录")
    @ApiImplicitParam(name = "VideoGroupId", value = "报修单编号", paramType = "query", required = true, dataType = "String")
    public ResultPojo deleteCheckRecordInfo(@RequestParam("VideoGroupId") String VideoGroupId, HttpServletRequest request) {
        return videoRelationInfoConsumeService.deleteVideoRelationInfo(VideoGroupId, ((UserDto) request.getAttribute("currentUser")).getPersonName());
    }
	
	/**
	 * 根据关联对象集合删除关联信息（视频编号和分组编号）；
	 * @param videoRelationInfoDto
	 * @return
	 */
	@PostMapping(value = { "/deleteVideoReletionByGroupIdAndVideoId" }, consumes = { "application/json; charset=UTF-8" }, produces = {
			"application/json; charset=UTF-8" })
	@ResponseBody
	@ApiOperation("根据关联对象集合删除关联信息（视频编号和分组编号）")
	public ResultPojo deleteVideoReletionByGroupIdAndVideoId(@RequestBody List<VideoRelationInfoDto> listVideoRelationInfoDto,
			HttpServletRequest request) {
		return videoRelationInfoConsumeService.deleteVideoReletionByGroupIdAndVideoId(listVideoRelationInfoDto, ((UserDto) request.getAttribute("currentUser")).getPersonName());
	}
}
